package com.itheima.demo;

import java.util.Random;
import java.util.Scanner;

public class demo3 {
    public static void main(String[] args) {
        //完成随机排名
        //定义一个动态初始化数组存储5名员工的工号
        int[] codes = new int[5];

        Scanner scanner = new Scanner(System.in);
        //循环5次，每次输入一个工号
        for (int i = 0; i < codes.length; i++) {
            System.out.println("请您输入当前第"+(i+1)+"名员工的工号：");
            int code = scanner.nextInt();
            codes[i] = code;
        }
        //打乱数组中的元素顺序
        Random random = new Random();
        for (int i = 0; i < codes.length; i++) {
            int index = random.nextInt(codes.length);
            int temp = codes[i];
            codes[i] = codes[index];
            codes[index] = temp;
        }
        //遍历数组，打印员工工号
        for (int i = 0; i < codes.length; i++) {
            System.out.println("第"+(i+1)+"名员工的工号是："+codes[i]);
        }
    }
}
